package cn.xfdzx.android.apps.shop.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import cn.xfdzx.android.apps.shop.R;

/**
 * @autor: zf
 * @Description: 选择分享方式
 * @Date: 2019/1/23 12:18
 */
public class ChooseShareTypeDialog extends Dialog implements View.OnClickListener {

    private Context context;
    private TextView tvCancelshare;
    private RelativeLayout rl_sharewx,rl_shareqq,rl_sharewb,rl_sharepyq,rl_shareqqzone;

    private setChoseTypeListener choseTypeListener;

    public ChooseShareTypeDialog(@NonNull Context activity) {
        super(activity, R.style.CustomDialog_Translucent);
        this.context = activity;
        setCanceledOnTouchOutside(true); // 点击空白区域可以Dismiss对话框
        setCancelable(true); // 点击返回按键可以Dismiss对话框
        init();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        init();
    }

    public void init() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_choseshare, null);
        setContentView(view);

        tvCancelshare = findViewById(R.id.tvCancelshare);
        rl_sharewx = findViewById(R.id.rl_sharewx);
        rl_sharepyq = findViewById(R.id.rl_sharepyq);
        tvCancelshare.setOnClickListener(this);
        rl_sharewx.setOnClickListener(this);
        rl_sharepyq.setOnClickListener(this);

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
        lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 高度设置为屏幕的0.6
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.rl_sharewx:
                choseTypeListener.onChoseType(1);
                break;
            case R.id.rl_sharepyq:
                choseTypeListener.onChoseType(2);
                break;
            case R.id.tvCancelshare:
                this.dismiss();
                break;
            default:
                this.dismiss();
                break;

        }
        this.dismiss();
    }
    public void setChoseTypeListener(setChoseTypeListener listener){
            this.choseTypeListener = listener;
    }

    public interface setChoseTypeListener {
        void onChoseType(int type);
    }
}
